package com.sjf.day01;

import java.util.Arrays;

/**
 *
 * @author <sjf753@qq.com>
 * @since 2021/12/4 10:43
 **/
public class bubbleSort {
    public static void select(int[] num){
        int n =num.length;
         for (int e=n-1;e>0;e--){
             boolean flag = true;
             for(int i=0;i<e;i++){
                 if(num[i]>num[i+1]){
                     swap(num,i,i+1);
                     flag=false;
                 }
             }
             System.out.println(Arrays.toString(num));
             if(flag) break;
         }
    }

    public static void swap(int[] a,int i,int j){
        a[i] = a[i] ^ a[j];
        a[j] = a[i] ^ a[j];
        a[i] = a[i] ^ a[j];
    }

    public static void main(String[] args) {
        int[] a =new int[]{5,4,2,3,1,9,7};
        select(a);
        //System.out.println(Arrays.toString(a));
    }
}
